# 测试时临时session
def getTempSession():
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker
    from urllib.parse import quote_plus as urlquote
    # engine = create_engine('postgresql://postgres:nurxat18903@127.0.0.1:5432/iPet')
    # engine = create_engine('postgresql://postgres:nurxat18903@47.108.130.44:5432/iPet')
    engine = create_engine(
        f'postgresql+psycopg2://system:{urlquote("Cetc@2024")}@172.16.110.79:54321/economic_cloud_dev')

    # 创建DBSession类型:
    DBSession = sessionmaker(bind=engine)
    """:type:Session"""
    return DBSession()


def kingQuery(sql):
    import psycopg2

    # 替换以下参数为你的 Kingbase 数据库连接信息
    connection = psycopg2.connect(
        user="system",
        password="Cetc@2024",
        host="172.16.110.79",
        port="54321",
        database="economic_cloud_dev"
    )

    cursor = connection.cursor()
    cursor.execute(sql)
    rows = cursor.fetchall()
    return rows


def kingInsert(sql):
    import psycopg2

    # 替换以下参数为你的 Kingbase 数据库连接信息
    connection = psycopg2.connect(
        user="system",
        password="Cetc@2024",
        host="172.16.110.79",
        port="54321",
        database="economic_cloud_dev"
    )

    cursor = connection.cursor()
    cursor.execute(sql)
    connection.commit()


def excute(sql):
    session = getTempSession()
    execute = session.execute(sql)
    results = execute.fetchall()
    return results
